#include "widget.h"
#include "ui_widget.h"
#include <QStack>
#include <math.h>
#include <string.h>
#include <iostream>
#include <string>
using namespace std;


Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setMaximumSize(200,290);
    this->setMinimumSize(200,290);
    this->setWindowTitle("计算器");

//    QFont f("仿宋"，10);
//    ui->mainlineEdit->setFont(f);
    ui->equabutton->setStyleSheet("background-color:blue");


}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_onebutton_clicked()
{
    expression +="1";
    ui->mainlineEdit->setText(expression);
}


void Widget::on_twobutton_clicked()
{
    expression +="2";
    ui->mainlineEdit->setText(expression);
}


void Widget::on_threebutton_clicked()
{
    expression +="3";
    ui->mainlineEdit->setText(expression);
}


void Widget::on_fourbutton_clicked()
{
    expression +="4";
    ui->mainlineEdit->setText(expression);
}


void Widget::on_fivebutton_clicked()
{
    expression +="5";
    ui->mainlineEdit->setText(expression);
}


void Widget::on_sixbutton_clicked()
{
    expression +="6";
    ui->mainlineEdit->setText(expression);
}


void Widget::on_severbutton_clicked()
{
    expression +="7";
    ui->mainlineEdit->setText(expression);
}


void Widget::on_eightbutton_clicked()
{
    expression +="8";
    ui->mainlineEdit->setText(expression);
}


void Widget::on_ninebutton_clicked()
{
    expression +="9";
    ui->mainlineEdit->setText(expression);
}


void Widget::on_zerobutton_clicked()
{
    expression +="0";
    ui->mainlineEdit->setText(expression);
}


void Widget::on_addbutton_clicked()
{
    expression +="+";
    ui->mainlineEdit->setText(expression);
}


void Widget::on_subbutton_clicked()
{
    expression +="-";
    ui->mainlineEdit->setText(expression);
}


void Widget::on_mulbutton_clicked()
{
    expression +="*";
    ui->mainlineEdit->setText(expression);
}


void Widget::on_divbutton_clicked()
{
    expression +="/";
    ui->mainlineEdit->setText(expression);
}


void Widget::on_leftbutton_clicked()
{
    expression +="(";
    ui->mainlineEdit->setText(expression);
}


void Widget::on_rightbutton_clicked()
{
    expression +=")";
    ui->mainlineEdit->setText(expression);
}


void Widget::on_delbutton_clicked()
{
    expression.chop(1);
    ui->mainlineEdit->setText(expression);
}


void Widget::on_clearbutton_clicked()
{
    expression.clear();
    ui->mainlineEdit->setText(expression);
}


void Widget::on_equabutton_clicked()
{


    char opt[128];
    std::string utf8Str = expression.toUtf8().constData();
    strcpy(opt,utf8Str.data());
//    cout << opt[strlen(opt)-1] << endl;
//    if (opt[strlen(opt)-1] != '=')
//    {
////        expression +="=";
//    }
    ui->mainlineEdit->setText(opt);

}



